package com.xinchao.ck_mips.utils;

import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
import android.widget.Toast;

import com.orhanobut.logger.Logger;
import com.xinchao.ck_mips.R;
import com.xinchao.ck_mips.bean.Orientation;
import com.xinchao.ck_mips.constant.CK;

/**
 * Created by wq on 2019/4/23.
 */
public class DisplayMetricsUtils {
    /**
     * 根据屏幕分辨率设置启动图
     *
     * @param act
     */
    public static void setBackground(Activity act) {
        try {
            DisplayMetrics metrics = new DisplayMetrics();
            act.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
            int height = metrics.heightPixels;
            int width = metrics.widthPixels;
            Logger.t(CK.TAG).d("分辨率:高" + metrics.heightPixels + "；宽:" + metrics.widthPixels + ";dpi:" + metrics.densityDpi + ";density:" + metrics.density);
            if (height > width) {
                act.getWindow().getDecorView().setBackgroundResource(R.drawable.splash_default_img);
            } else {
                act.getWindow().getDecorView().setBackgroundResource(R.drawable.splash_landscape_img);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取设备横竖屏
     *
     * @param mContext
     * @return
     */
    public static Orientation getScreenOrientation(Context mContext) {
        WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        DisplayMetrics dm = new DisplayMetrics();
        display.getRealMetrics(dm);
        return dm.heightPixels > dm.widthPixels ? Orientation.PORTRAIT : Orientation.LANDSCAPE;
    }

}
